package org.i1510.common.service.CxfInterceptor;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import org.apache.ws.security.WSPasswordCallback;

public class WsOutAuthHandler implements CallbackHandler {

	public void handle(Callback[] callbacks) throws IOException,
			UnsupportedCallbackException {
		for (int i = 0; i < callbacks.length; i++) {
			WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
			int usage = pc.getUsage();
			if (usage == WSPasswordCallback.USERNAME_TOKEN) {
				System.out.println("USERNAME_TOKEN");
				// username token pwd...
				// UsernameToken的用户名的密码
				pc.setPassword("123456");

			} else if (usage == WSPasswordCallback.SIGNATURE) {
				// set the password for client's
				// keystore.keyPassword
				// 密钥库的密码
				pc.setPassword("keyPassword");
			}
		}
	}
}